package com.lengxf.netty.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.Objects;

@Slf4j
@Getter
@AllArgsConstructor
public enum ChannelTypeEnum {

    TYPE1("type1", "类型1"),
    TYPE2("type2", "类型2");

    private final String code;

    private final String desc;

    /**
     * 根据编码获取枚举值
     */
    public static ChannelTypeEnum getEnumByCode(String code) {
        return Arrays.stream(ChannelTypeEnum.values())
                .filter(it -> Objects.equals(code, it.code))
                .findFirst().orElseThrow(() -> {
                    log.error("通道类型错误,编码为：{}", code);
                    throw new RuntimeException("通道类型错误");
                });
    }

}
